home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Email Clients / Talk-n-Mail.exe / _SETUP.1 / $TNM$_Music.js < prev    next >
Encoding:
JavaScript  |  2001-04-22  |  4.0 KB  |  205 lines

  1. /*     JavaScript for Talk-n-Mail
  2.     Copyright (c) 1999-2001, SoftApproach Corp. All rights reserved
  3. */
  4.  
  5. // Sound/Music information array
  6. // [0] is for main sound (speech)
  7. var iarMusic
  8.  
  9. /* Data object for a Div */
  10. function fobjMusicMakeDataObject()
  11. {
  12.     // Embedded sound
  13.     this.objEmbed = 0
  14.     this.lLength = 0
  15.     return this
  16. }
  17.  
  18. // Make a blank array
  19. function faryMusicMakeArray(aiUBound) 
  20. {
  21.         for (var i = 0; i <= aiUBound; i++) 
  22.     {
  23.         this[i] = new fobjMusicMakeDataObject()
  24.     }
  25.  
  26.     // Number of music
  27.     this.iiMusicCount = 0
  28.     
  29.     // Times to repeat for all music
  30.     this.ilMusicPlayCount = 0
  31.     
  32.     // Pick up the next one randomly?
  33.     this.ibMusicPlayRandom = false
  34.  
  35.     // Current music index
  36.     this.iiMusicIndex = 0
  37.  
  38.     // The current Mouse Click sound
  39.     this.divAniSound = ''
  40.  
  41.     // Total numbers of music to play, countdown
  42.     this.llMusicPlayCountDown = 0
  43.  
  44.     // The Timeout function call id
  45.     this.ilNextMusicId = 0
  46.     // Turned off already?
  47.     this.bSoundOff = false
  48.  
  49.  
  50.     return this
  51. }
  52.  
  53. // Main speech
  54. function fbHasSpeech(){return iarMusic[0].lLength > 0}
  55. // Additional music
  56. function fbHasMusic(){return iarMusic.iiMusicCount > 0}
  57.  
  58. // Turn on the speech then play all music
  59. function fvPageSoundOn()
  60. {
  61.  
  62.     // Has speech?
  63.     if(fbHasSpeech()) 
  64.         iarMusic.iiMusicIndex = -1
  65.     // No music either?
  66.     else if(!fbHasMusic()) 
  67.     {
  68.         // Hide the buttons
  69.         fvShow("divSound", false)
  70.         return 
  71.     }
  72.     else
  73.         iarMusic.iiMusicIndex = 0
  74.     // End if
  75.  
  76.     // Number of additional music to play, 0 is forever
  77.     iarMusic.llMusicPlayCountDown = iarMusic.ilMusicPlayCount ?
  78.         iarMusic.iiMusicCount * iarMusic.ilMusicPlayCount : 99999
  79.  
  80.     // To go
  81.     iarMusic.bSoundOff = false
  82.     fvMusicPlayOne()
  83. }
  84.  
  85. // Get one music to play and how long it will last
  86. function fiGetMusic() 
  87. {
  88. var liIndex = iarMusic.iiMusicIndex
  89.  
  90.     // Time for main speech?
  91.     // Play once and once only
  92.     if(liIndex == -1)  
  93.     {
  94.         liIndex = fbHasSpeech() ? 0 : -1
  95.     }
  96.     // No music or total # of time finished?
  97.     else if(!fbHasMusic() || iarMusic.llMusicPlayCountDown <= 0)
  98.     {
  99.         liIndex = -1
  100.     }
  101.     // Sequencial / one music only
  102.     else if(!iarMusic.ibMusicPlayRandom || iarMusic.iiMusicCount == 1)
  103.     {
  104.         liIndex ++
  105.         if(liIndex > iarMusic.iiMusicCount) liIndex = 1
  106.     }
  107.     // Random
  108.     else
  109.     {
  110.         while(true)
  111.         {
  112.             liIndex = 1 + Math.floor(fiRandom() * iarMusic.iiMusicCount)
  113.             if(liIndex != iarMusic.iarMusic.iiMusicIndex) break
  114.         }
  115.             
  116.     }
  117.  
  118.     // Music picked?
  119.     // One played
  120.     if(liIndex > 0){iarMusic.llMusicPlayCountDown --}
  121.  
  122.     // Keep
  123.     iarMusic.iiMusicIndex = liIndex
  124.     return liIndex
  125. }
  126.  
  127. // Called from $TNM$_Ani.js for mouse click sound
  128. function fvPlayMusic(divDiv)
  129. {
  130.     // No more main 
  131.     fvPlayMusicEx(divDiv, true)
  132. }
  133.  
  134. // Play one music
  135. function fvMusicPlayOne()
  136. {
  137. var liIndex
  138. var llDuration
  139.  
  140.     // Off but coming in again because of the timer?
  141.     if(iarMusic.bSoundOff) return
  142.  
  143.     liIndex = fiGetMusic()
  144.  
  145.     // No more
  146.     if(liIndex < 0) return
  147.  
  148.     fvPlayMusicEx(iarMusic[liIndex].objEmbed, false)
  149.         
  150.     // Come back again for the next one
  151.     llDuration = iarMusic[liIndex].lLength
  152.     iarMusic.ilNextMusicId = setTimeout('fvMusicPlayOne()', llDuration)
  153.  
  154. }
  155. // Turn all the sound off
  156. function fvPageSoundOff()
  157. {
  158.     // To stop
  159.     if(iarMusic.ilNextMusicId) clearTimeout(iarMusic.ilNextMusicId)
  160.     iarMusic.bSoundOff = true
  161.     iarMusic.iiMusicIndex = 0
  162.  
  163.     if(ibIsIE)
  164.     {
  165.         sndBackgroundSound.src = ''
  166.     }
  167.     else
  168.     {
  169.         // Main speech / music
  170.         if(iarMusic[iarMusic.iiMusicIndex].objEmbed)
  171.             iarMusic[iarMusic.iiMusicIndex].objEmbed.stop()
  172.  
  173.         // Mouse click sound
  174.         if(iarMusic.divAniSound) iarMusic.divAniSound.stop()
  175.     }
  176. }
  177. function fvPlayMusicEx(divDiv, abTurnOffMain)
  178. {
  179.     // Turn off the main speech/music
  180.     if(abTurnOffMain)
  181.     {
  182.         fvPageSoundOff()
  183.     }
  184.  
  185.     if(ibIsIE)
  186.     {
  187.         sndBackgroundSound.src = ''
  188.  
  189.         if(divDiv.src)             
  190.             sndBackgroundSound.src = divDiv.src
  191.         else
  192.             sndBackgroundSound.src = divDiv
  193.         // End if
  194.  
  195.  
  196.         sndBackgroundSound.volume = 0
  197.     }
  198.     else
  199.     {
  200.         divDiv.play()
  201.         iarMusic.divAniSound = divDiv
  202.     }
  203. }
  204.  
  205.